package org.jiamandan.com.config;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jiamandan.com.utils.RedisUtil;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @version Revision 1.0.1
 * @版权：版权所有 (c) 2021
 * @author:Lee
 * @email:honvy.lee@qq.com
 * @see:
 * @创建日期：2022-10-21 15:53
 * @功能说明：
 * @begin
 * @修改记录:
 * @修改后版本 修改人        修改内容
 * @2022-10-21 15:53	         Lee        	创建
 * @end
 */
@Async
@Component
@Slf4j
@AllArgsConstructor
public class NettyStartListener implements ApplicationRunner {

    private NettyServer nettyServer;
    private NettyProperties nettyProperties;
    private RedisUtil redisUtil;
    @Override
    public void run(ApplicationArguments args) throws Exception {

        log.info("========================================");
        log.info("开始启动 Netty 服务器");
        log.info("配置参数:");
        log.info("  Boss 线程数: {}", nettyProperties.getBossThread());
        log.info("  Worker 线程数: {}", nettyProperties.getWorkerThread());
        // 应改为：
        log.info("  读超时: {}秒, 写超时: {}秒, 读写超时: {}秒",
        nettyProperties.getReaderIdleTime(),
        nettyProperties.getWriterIdleTime(),
        nettyProperties.getAllIdleTime());
        log.info("  监听端口: {}", nettyProperties.getPorts());
        log.info("========================================");

        // 启动服务器
        this.nettyServer.startNettyServer(nettyProperties.getPorts());
    }
}
